import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:grab_the_order/app/modules/profile/profile_controller.dart';
import 'package:grab_the_order/core/values/app_styles.dart';

class ProfileView extends GetView<ProfileController> {
  const ProfileView({Key? key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: const Text('个人中心'),
      ),
      body: SingleChildScrollView(
        padding: const EdgeInsets.symmetric(vertical: 20, horizontal: 16),
        child: Column(
          children: [
            _buildUserInfoCard(),
            const SizedBox(height: 20),
            _buildMenuList(),
          ],
        ),
      ),
    );
  }

  // 用户信息卡片
  Widget _buildUserInfoCard() {
    return Container(
      padding: const EdgeInsets.all(20),
      decoration: modernDecoration(),
      child: Row(
        children: [
          const CircleAvatar(
            radius: 30,
            backgroundColor: kPrimaryColor,
            child: Icon(Icons.person, color: Colors.white, size: 30),
          ),
          const SizedBox(width: 15),
          Column(
            crossAxisAlignment: CrossAxisAlignment.start,
            children: [
              Text(
                "尊贵的用户",
                style: TextStyle(
                  fontSize: 18,
                  fontWeight: FontWeight.bold,
                  color: Colors.grey[800],
                ),
              ),
              const SizedBox(height: 5),
              const Text(
                "欢迎使用抢单助手",
                style: TextStyle(
                  fontSize: 14,
                  color: Colors.grey,
                ),
              ),
            ],
          ),
        ],
      ),
    );
  }

  // 功能菜单列表
  Widget _buildMenuList() {
    return Container(
      decoration: modernDecoration(),
      child: Column(
        children: [
          _buildMenuItem(
            icon: Icons.shield_outlined,
            title: "权限自检中心",
            onTap: controller.navigateToPermissionCheck,
          ),
          _buildDivider(),
          _buildMenuItem(
            icon: Icons.history,
            title: "运行日志", // 原 "抢单日志"
            onTap: controller.navigateToLog, // 【已修改】
          ),
          _buildDivider(),
          _buildMenuItem(
            icon: Icons.bar_chart,
            title: "数据统计",
            onTap: () {
              Get.snackbar("提示", "该功能正在开发中...");
            },
          ),
          _buildDivider(),
          _buildMenuItem(
            icon: Icons.info_outline,
            title: "关于我们",
            onTap: () {
              Get.snackbar("提示", "抢单助手 v1.0.0");
            },
          ),
        ],
      ),
    );
  }

  // 菜单项封装
  Widget _buildMenuItem({
    required IconData icon,
    required String title,
    required VoidCallback onTap,
  }) {
    return ListTile(
      leading: Icon(icon, color: kPrimaryColor),
      title: Text(title, style: const TextStyle(fontSize: 16)),
      trailing: const Icon(Icons.chevron_right, color: Colors.grey),
      onTap: onTap,
    );
  }

  // 分割线
  Widget _buildDivider() {
    return Divider(
      height: 1,
      thickness: 1,
      color: Colors.grey[200],
      indent: 16,
      endIndent: 16,
    );
  }
}
